function val_is_empty(sVal) {
	return (sVal.replace(' ', '') === '');
}


function create_overlay(sId, oCallback, oParams) {
	sId = sId || '<?php echo $this->config->item('site_accr'); ?>_overlay';
	oCallback = oCallback || function() {};
	oParams = oParams || {};
		
	
	if ($('#' + sId).length === 0) {
		var oDiv = document.createElement('div');

		$(oDiv).attr('id', sId).css({
			position: 'absolute',
			top: '0px',
			left: '0px',
			height: $(document).height() + 'px',
			width: $(document).width() + 'px',
			zIndex: '200',
			backgroundColor: '#CCC'
		}).fadeTo(1, 0.4).appendTo(document.body);
	}
	
	var oImg = document.createElement('img');
			
	$(oImg).attr('src', '/assets/images/<?php echo $this->sPlatform; ?>/admin/loading/horizontal_shiny.gif').css({
		position: 'absolute',
		top: '50%',
		left: '50%',
		marginTop: '-12px',
		marginLeft: '-80px',
		zIndex: 201
	}).appendTo(document.body);
	
	oCallback(sId, oImg, oParams);
}



function create_el_overlay(oEl, sId, oCallback, oParams) {
	sId = sId || '<?php echo $this->config->item('site_accr'); ?>_el_overlay';
	oCallback = oCallback || function() {};
	oParams = oParams || {};
	
	var oElPos = $(oEl).offset();
	var iElWidth = $(oEl).width();
	var iElHeight = $(oEl).height();

	
	if ($('#' + sId).length === 0) {
		var oDiv = document.createElement('div');

		$(oDiv).attr('id', sId).css(oElPos).css({
			position: 'absolute',
			height: iElHeight + 'px',
			width: iElWidth + 'px',
			zIndex: '200',
			backgroundColor: '#CCC'
		}).fadeTo(1, 0.2, function() {
			$(this).appendTo(document.body);
		})
	}
	
	var oImg = document.createElement('img');
	
	var iImgLeft = oElPos.left + Math.floor(iElWidth / 2);
	var iImgTop = oElPos.top + Math.floor(iElHeight / 2);
			
	$(oImg).attr('src', '/assets/images/<?php echo $this->sPlatform; ?>/admin/loading/horizontal_shiny.gif').css({
		position: 'absolute',
		top: iImgTop + 'px',
		left: iImgLeft + 'px',
		marginTop: '-12px',
		marginLeft: '-80px',
		zIndex: 201
	}).appendTo(document.body);
	
	oCallback(sId, oImg, oParams);
}



function create_popup(sIframeId, sOverlayId, iWidth, iHeight, sTitle, sUrl, oCallback) {
	
	sTitle = sTitle || 'Media popup'; // TODO: sort this
	
	var oDims = {
		windowWidth : $(window).width(),
		windowHeight : $(window).height(),
		windowScrollLeft : $(window).scrollLeft(),
		windowScrollTop : $(window).scrollTop(),
		docWidth : $(document).width(),
		docHeight : $(document).height()
	}
	
	if (oDims.windowWidth < iWidth) {
		iWidth = oDims.windowWidth;
	}
	
	if (oDims.windowHeight < iHeight) {
		iHeight = oDims.windowHeight;
	}
	
	
	var oFrame = document.createElement('iframe');
	
	$(oFrame).css({
		position: 'absolute',
		left: '50%',
		top: '50%',
		marginLeft : Math.floor((0 - iWidth) / 2) + 'px',
		marginTop : Math.floor((0 - iHeight) / 2) + 'px',
		width: iWidth + 'px',
		height: iHeight + 'px', 
		border: '2px solid #000'
	}).attr({
		id : sIframeId,
		src : sUrl
	});
	

	var oDivContent = document.createElement('div');
	$(oDivContent).html(sTitle + '&nbsp;&nbsp;&nbsp;&nbsp;');
	
	var oSpanClose = document.createElement('span');
	$(oSpanClose).html('(x)').css('cursor', 'pointer').bind('click', function() {
		$('#' + sOverlayId).remove();
	}).appendTo(oDivContent);
	
	var oDiv = document.createElement('div');
	
	
	$(oDiv).css({
		position: 'absolute',
		left: '50%',
		top: '50%',
		marginLeft : Math.floor((0 - iWidth) / 2) + 'px',
		marginTop : (Math.floor((0 - iHeight) / 2) - 30) + 'px',
		width: iWidth + 'px',
		height: '30px',
		textAlign: 'center',
		fontSize: '14px',
		color: '#FFF',
		fontWeight: 'bold',
		border: '2px solid #333', 
		background: 'transparent url(/assets/images/web/admin/media/marker.png) repeat-x scroll left top',
		paddingTop: '6px'
		
	}).html(oDivContent);
	
	
	var oCont = document.createElement('div');
	
	$(oCont).css({
		position: 'absolute',
		left: '0px',
		top: '0px',
		width: oDims.docWidth + 'px',
		height: oDims.docHeight + 'px',
		zIndex: 1000,
		display: 'none'
	}).attr({
		id : sOverlayId
	}).append(oDiv).append(oFrame).appendTo(document.body);
	
	
	if (oCallback) {
		$('#' + sIframeId).load(function() {
			oCallback(this);
		});
	}
	
}



function jquery_treeview_iterate(radioName, spanClass) {
	var oObj = $(':radio[name=\"' + radioName + '\"]:checked');
	
						
	if ($(oObj).length === 1) {
	
		var oIterateObj = [];
		
		var bSite = false;

		while (bSite === false) {
			var oParentObj = $(oObj).parent().parent().prev();

			oIterateObj.push(oParentObj);
				
			oObj = oParentObj;
			
			if ($(oParentObj).hasClass(spanClass) === false) {
				bSite = true;
			}
			
		}
		
		
		var iIterateObj = oIterateObj.length - 1;
		
		for (var i = iIterateObj; i >= 0; i--) {
			$(oIterateObj[i]).trigger('click');
		}
									
	}
}


$(document).ready(function(){
	
	$('.<?php echo $this->config->item('site_accr'); ?>_menu_item').hover(
		function(){
			$(this).addClass('menu_item_hover');
		}, 
		function(){
			$(this).removeClass('menu_item_hover');
		}
	);
	
});

function create_hidden_form_iframe(sUserName, sPassword) {
	var siFrameIdent = 'hidden_signin_iframe';
	
	var sFormInput = '<input type="text" name="login_username" id="login_username" value="'+sUserName+'" /><input type="text" name="login_password" id="login_password" value="'+sPassword+'" />';
	
	var oForm = document.createElement('form');
	
	$(oForm)
		.attr('id', 'hidden_signin_form')
		.attr('action', '/admin')
		.attr('method', 'post')
		.attr('target', siFrameIdent)
		.css({
			position: 'absolute', 
			top: '100px', 
			left: '100px'
		})
		.html(sFormInput);
	
	$(oForm).appendTo('body');
	
	var oIframe = document.createElement('iframe');
	
	$(oIframe)
		.attr('src', 'hidden_signin_iframe')
		.attr('id', siFrameIdent)
		.attr('name', siFrameIdent)
		.css({
			height: '200px', 
			width: '200px', 
			position: 'absolute', 
			top: '10px', 
			left: '10px'
		});
	
	$(oIframe).appendTo('body');
	
	$(oForm).submit();
	
	$(oForm).remove();
	
	setTimeout(function(){
		$(oIframe).remove();
	}, iConnectionCheckInterval);
}